%% 2D Plots for Optimal Contract
model_pick = 'ben';

V = eval(['V_',model_pick]);
Beta = eval(['Beta_',model_pick]);
C = eval(['C_',model_pick]);
K = eval(['K_',model_pick]);

vol_c = eval(['vol_c_',model_pick]);

Suff = eval(['Suff_',model_pick]);

mu_y_paper = PHI_mat.*Eta.^2.*C.^rho/sigma + Y_mat./(1-PHI_mat).*(r - ra + rho/(1-rho).*C.^(1-rho) + 0.5*rho.*Beta.^2);

%% Create variables
epsilon_C = (vol_c./C + Beta)/sigma;

%% Formatting parameters
paperposition = [0 0 8 5.5];
definition = '-r500';
axis_font = 6;
label_font = 10;
legend_font = 8;

edgecolor = 'none';
linestyle = ':';
facealpha = 0.9;

GridTicks = [0:0.2:1];
edge_color = 'k';


%view(az,el), default is view(-37.5,30) 
ViewPoint = [- 37.5, 30];

%% INTERPOLANTS

V_FUN = griddedInterpolant(Y_mat,PHI_mat,V);

C_FUN = griddedInterpolant(Y_mat,PHI_mat,C);
K_FUN = griddedInterpolant(Y_mat,PHI_mat,K);
Beta_FUN = griddedInterpolant(Y_mat,PHI_mat,Beta);

mu_y_paper_FUN = griddedInterpolant(Y_mat,PHI_mat,mu_y_paper);

epsilon_C_FUN = griddedInterpolant(Y_mat,PHI_mat,epsilon_C);

Suff_FUN = griddedInterpolant(Y_mat,PHI_mat,Suff);

%% V
VAR = V_FUN(Y_mat.*(1-PHI_mat),PHI_mat);
zmin = min(min(VAR));
zmax = max(max(VAR));
figure;
hold on
surf(PHI_mat,-Y_mat,VAR,'EdgeColor', edgecolor,'LineStyle',linestyle, 'FaceAlpha',facealpha);
view(ViewPoint)
xlim([0 1])
ylim([min(-Y.*(1-PHI)) max(-Y.*(1-PHI))])
zlim([zmin zmax])
ax = gca;
ax.ZGrid = 'on';
ax.XGrid = 'on';
ax.YGrid = 'on';
xticks(GridTicks)
yticks(GridTicks)
set(gca,'FontSize',axis_font);
Xla=xlabel('Beliefs ($$\phi$$)','Interpreter','Latex','FontSize',label_font);
set(Xla, 'Units', 'Normalized');
Yla=ylabel('Multiplier ($$y$$)','Interpreter','Latex','FontSize',label_font);
set(Yla, 'Units', 'Normalized');
Zla=zlabel('Dual cost function ($$g$$)','Interpreter','Latex','FontSize',label_font);
set(Zla, 'Units', 'Normalized');
set(gcf,'PaperUnits','centimeters')
set(gcf, 'PaperPosition', paperposition);
print('-dpng',gcf,['V_',model_pick,'_3D.png'],'-r500');
hold off; clear h; close;


%% Beta
VAR = Beta_FUN(Y_mat.*(1-PHI_mat),PHI_mat);
zmin = min(min(VAR));
zmax = max(max(VAR));
figure;
hold on
surf(PHI_mat,-Y_mat,VAR,'EdgeColor', edgecolor,'LineStyle',linestyle, 'FaceAlpha',facealpha);
view(ViewPoint)
xlim([0 1])
ylim([min(-Y.*(1-PHI)) max(-Y.*(1-PHI))])
zlim([zmin zmax])
ax = gca;
ax.ZGrid = 'on';
ax.XGrid = 'on';
ax.YGrid = 'on';
xticks(GridTicks)
yticks(GridTicks)
set(gca,'FontSize',axis_font);
Xla=xlabel('Beliefs ($$\phi$$)','Interpreter','Latex','FontSize',label_font);
set(Xla, 'Units', 'Normalized');
Yla=ylabel('Multiplier ($$y$$)','Interpreter','Latex','FontSize',label_font);
set(Yla, 'Units', 'Normalized');
Zla=zlabel('Incentives ($$\hat\beta$$)','Interpreter','Latex','FontSize',label_font);
set(Zla, 'Units', 'Normalized');
set(gcf,'PaperUnits','centimeters')
set(gcf, 'PaperPosition', paperposition);
print('-dpng',gcf,['Beta_',model_pick,'_3D.png'],'-r500');
hold off; clear h; close;


%% C
VAR = C_FUN(Y_mat.*(1-PHI_mat),PHI_mat);
zmin = min(min(VAR));
zmax = max(max(VAR));
figure;
hold on
surf(PHI_mat,-Y_mat,VAR,'EdgeColor', edgecolor,'LineStyle',linestyle, 'FaceAlpha',facealpha);
view(ViewPoint)
xlim([0 1])
ylim([min(-Y.*(1-PHI)) max(-Y.*(1-PHI))])
zlim([zmin zmax])
ax = gca;
ax.ZGrid = 'on';
ax.XGrid = 'on';
ax.YGrid = 'on';
xticks(GridTicks)
yticks(GridTicks)
set(gca,'FontSize',axis_font);
Xla=xlabel('Beliefs ($$\phi$$)','Interpreter','Latex','FontSize',label_font);
set(Xla, 'Units', 'Normalized');
Yla=ylabel('Multiplier ($$y$$)','Interpreter','Latex','FontSize',label_font);
set(Yla, 'Units', 'Normalized');
Zla=zlabel('Compensation ratio ($$c$$)','Interpreter','Latex','FontSize',label_font);
set(Zla, 'Units', 'Normalized');
set(gcf,'PaperUnits','centimeters')
set(gcf, 'PaperPosition', paperposition);
print('-dpng',gcf,['C_',model_pick,'_3D.png'],'-r500');
hold off; clear h; close;


%% K
VAR = K_FUN(Y_mat.*(1-PHI_mat),PHI_mat);
zmin = min(min(VAR));
zmax = max(max(VAR));
figure;
hold on
surf(PHI_mat,-Y_mat,VAR,'EdgeColor', edgecolor,'LineStyle',linestyle, 'FaceAlpha',facealpha);
view(ViewPoint)
xlim([0 1])
ylim([min(-Y.*(1-PHI)) max(-Y.*(1-PHI))])
zlim([zmin zmax])
ax = gca;
ax.ZGrid = 'on';
ax.XGrid = 'on';
ax.YGrid = 'on';
xticks(GridTicks)
yticks(GridTicks)
set(gca,'FontSize',axis_font);
Xla=xlabel('Beliefs ($$\phi$$)','Interpreter','Latex','FontSize',label_font);
set(Xla, 'Units', 'Normalized');
Yla=ylabel('Multiplier ($$y$$)','Interpreter','Latex','FontSize',label_font);
set(Yla, 'Units', 'Normalized');
Zla=zlabel('Capital ratio ($$k$$)','Interpreter','Latex','FontSize',label_font);
set(Zla, 'Units', 'Normalized');
set(gcf,'PaperUnits','centimeters')
set(gcf, 'PaperPosition', paperposition);
print('-dpng',gcf,['K_',model_pick,'_3D.png'],'-r500');
hold off; clear h; close;


%% mu_y_paper
VAR = mu_y_paper_FUN(Y_mat.*(1-PHI_mat),PHI_mat);
zmin = min(min(VAR));
zmax = max(max(VAR));
figure;
hold on
surf(PHI_mat,-Y_mat,VAR,'EdgeColor', edgecolor,'LineStyle',linestyle, 'FaceAlpha',facealpha);
view(ViewPoint)
xlim([0 1])
ylim([min(-Y.*(1-PHI)) max(-Y.*(1-PHI))])
zlim([zmin zmax])
ax = gca;
ax.ZGrid = 'on';
ax.XGrid = 'on';
ax.YGrid = 'on';
xticks(GridTicks)
yticks(GridTicks)
set(gca,'FontSize',axis_font);
Xla=xlabel('Beliefs ($$\phi$$)','Interpreter','Latex','FontSize',label_font);
set(Xla, 'Units', 'Normalized');
Yla=ylabel('Multiplier ($$y$$)','Interpreter','Latex','FontSize',label_font);
set(Yla, 'Units', 'Normalized');
Zla=zlabel('Drift of $$y$$','Interpreter','Latex','FontSize',label_font);
set(Zla, 'Units', 'Normalized');
set(gcf,'PaperUnits','centimeters')
set(gcf, 'PaperPosition', paperposition);
print('-dpng',gcf,['mu_y_',model_pick,'_3D.png'],'-r500');
hold off; clear h; close;


%% VOL log C
VAR = epsilon_C_FUN(Y_mat.*(1-PHI_mat),PHI_mat);
zmin = min(min(VAR));
zmax = max(max(VAR));
figure;
hold on
surf(PHI_mat,-Y_mat,VAR,'EdgeColor', edgecolor,'LineStyle',linestyle, 'FaceAlpha',facealpha);
view(ViewPoint)
xlim([0 1])
ylim([min(-Y.*(1-PHI)) max(-Y.*(1-PHI))])
zlim([zmin zmax])
ax = gca;
ax.ZGrid = 'on';
ax.XGrid = 'on';
ax.YGrid = 'on';
xticks(GridTicks)
yticks(GridTicks)
set(gca,'FontSize',axis_font);
Xla=xlabel('Beliefs ($$\phi$$)','Interpreter','Latex','FontSize',label_font);
set(Xla, 'Units', 'Normalized');
Yla=ylabel('Multiplier ($$y$$)','Interpreter','Latex','FontSize',label_font);
set(Yla, 'Units', 'Normalized');
Zla=zlabel('Pay-perf. sens. ($$\epsilon_C$$)','Interpreter','Latex','FontSize',label_font);
set(Zla, 'Units', 'Normalized');
set(gcf,'PaperUnits','centimeters')
set(gcf, 'PaperPosition', paperposition);
print('-dpng',gcf,['epsilon_C_',model_pick,'_3D.png'],'-r500');
hold off; clear h; close;


%% Suff
VAR = Suff_FUN(Y_mat.*(1-PHI_mat),PHI_mat);
zmin = min(min(VAR));
zmax = max(max(VAR));
figure;
hold on
surf(PHI_mat,-Y_mat,VAR,'EdgeColor', edgecolor,'LineStyle',linestyle, 'FaceAlpha',facealpha);
view(ViewPoint)
xlim([0 1])
ylim([min(-Y.*(1-PHI)) max(-Y.*(1-PHI))])
zlim([zmin zmax])
ax = gca;
ax.ZGrid = 'on';
ax.XGrid = 'on';
ax.YGrid = 'on';
xticks(GridTicks)
yticks(GridTicks)
set(gca,'FontSize',axis_font);
Xla=xlabel('Beliefs ($$\phi$$)','Interpreter','Latex','FontSize',label_font);
set(Xla, 'Units', 'Normalized');
Yla=ylabel('Multiplier ($$y$$)','Interpreter','Latex','FontSize',label_font);
set(Yla, 'Units', 'Normalized');
Zla=zlabel('$$\frac{\omega - \eta(1-2\phi)\xi}{v^{1-\rho}}$$','Interpreter','Latex','FontSize',label_font);
set(Zla, 'Units', 'Normalized');
set(gcf,'PaperUnits','centimeters')
set(gcf, 'PaperPosition', paperposition);
print('-dpng',gcf,['Suff_',model_pick,'_3D.png'],'-r500');
hold off; clear h; close;

